import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', {
    state: () => ({
        count: 0
    }),
    getters: {
        doubleCount: (state) => state.count * 2,
        doublePlusOne() {
            //this获取其他getters
            return this.doubleCount + 1
        }
    },
    actions: {
        //可以异步
        increment() {
            this.count++
        }
    },
    // 开启数据缓存,pinia-plugin-persist插件效果
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'myCounter', // 存储的 key 值，默认为 storeId
                storage: localStorage, // 存储的位置，默认为 sessionStorage
                paths: ['count'], // 需要存储的 state 状态，默认存储所有的状态
            }
        ]
    }

})